*Working directory
clear
cd "C:\Users\Zeljko\Desktop\Political Communication - Replication Materials" // Note: Change the working directory

import excel "final_data.xlsx", sheet("Sheet1") firstrow 
gen date_new = dofc(date)
gen year=year(date_new) 
egen party_id = group(party)
egen qt = group(con date)
egen partyqt = group(party_id qt)
merge m:m qt party_id issue using "ownership_data.dta"
drop _merge

save "final_data_1.dta", replace
collapse(sum) n_attack, by (partyqt) //Generating total number of attacks by a party on a QT (needed to calculate DV)
rename n_attack total_n_attack

save "attack_total.dta", replace
merge m:m partyqt using "final_data_1.dta"

drop if ownership == . // Omitting parties not present in QT and parties that lack ownership data
drop _merge
egen dyad = group(party_subject issue)
egen issue_id = group(issue)
gen attack_attention = n_attacks/total_n_attack // Generating DV
replace attack_attention = 0 if attack_attention == . 
save "final_data_2.dta", replace


*Merging salience
clear
use "final_data_2.dta", replace
merge m:m qt issue using "ena_data.dta"
drop if con == .
drop _merge
merge m:m qt issue using "ipsos_data.dta"
drop if con == .
drop _merge
save "final_data_3.dta", replace

*DESCRIPTIVES
clear
use "final_data_3.dta", replace
bysort con: sum attack_attention ownership news_salience ipsos_share // Table 2
collapse(mean) attack_attention, by(con issue qt)
graph box attack_attention, over(issue), if con == 1 // Figure 1 (left)
graph box attack_attention, over(issue), if con == 3 // Figure 2 (right)

*MAIN RESULTS  (TABLE 3)
*BELGIUM
clear
use "final_data_3.dta", replace
keep if con == 1

*Model empty - BELGIUM
mixed  attack_attention || _all:R.dyad || qt:
estat ic

*Model 1 - BELGIUM
mixed  attack_attention c.ownership c.news_salience i.minister_role c.election_m i.niche i.gov i.issue_id i.year || _all:R.dyad || qt:
estat ic

*Model 2 - BELGIUM
mixed  attack_attention c.ownership##c.news_salience i.minister_role c.election_m i.niche i.gov i.issue_id i.year || _all:R.dyad || qt:
estat ic

*Figure 2 - BELGIUM
margins, at(news_salience=(0(.02).20) ownership=(.00 .342)) atmeans level(90)
marginsplot,  recast(line)


*UK
clear
use "final_data_3.dta", replace
keep if con == 3

*Model empty - UK
mixed  attack_attention || _all:R.dyad || qt:
estat ic

*Model 1 - UK
mixed  attack_attention c.ownership c.ipsos_share c.election_m i.issue_id i.year || _all:R.dyad || qt:
estat ic

*Model 2 - UK
mixed  attack_attention c.ownership##c.ipsos_share c.election_m i.issue_id i.year || _all:R.dyad || qt:
estat ic

margins, at(ipsos_share=(.0(.05).60) ownership=(.175 .325)) atmeans level(90)
marginsplot,  recast(line)
